<template>
	<view class="container">
	  <view class="example">
	    <uni-forms ref="form" :model="PigLiveList" labelWidth="80px">
	      <uni-forms-item label="母猪耳号" name="pigCode">
	        <uni-easyinput v-model="PigLiveList.pigCode" placeholder="请输入猪只耳号" />
	      </uni-forms-item>
	      <uni-forms-item label="公猪耳号" name="pigFatherCode">
	        <uni-easyinput v-model="PigLiveList.pigFatherCode" placeholder="请输入公猪耳号" />
	      </uni-forms-item>

	      <uni-forms-item label="分娩方式" name="pigLiveType" required>
				<!-- 下拉框选择 -->
				<uni-data-select
				 v-model="PigLiveList.pigLiveType"
				 :localdata="pigLiveTypes"
				 @change="change">
				 </uni-data-select>
	      </uni-forms-item>
		  <uni-forms-item label="妊娠天数" name="pregnancyDays">
		    <uni-easyinput v-model="PigLiveList.pregnancyDays" placeholder="请输入妊娠天数(单位 天)" />
		  </uni-forms-item>
		<uni-forms-item label="配种管理员" name="pigLiveManager" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="PigLiveList.pigLiveManager"
			 :localdata="staffNameList">
			 </uni-data-select>
		</uni-forms-item>
		<view class="example-body">
			<uni-forms-item label="分娩时间" name="pigLiveDatetime">
			  <uni-datetime-picker type="datetime" v-model="datetimesingle" @change="changeLog" />
			</uni-forms-item>
		</view>
		<uni-forms-item label="分娩时长" name="pigLiveTime">
		  <uni-easyinput v-model="PigLiveList.pigLiveTime" placeholder="请输入分娩时长(单位 h)" />
		</uni-forms-item>
		<uni-forms-item label="已产胎次" name="pigLivedNum">
		  <uni-easyinput v-model="PigLiveList.pigLivedNum" placeholder="请输入已产胎次(单位 次)" />
		</uni-forms-item>
		<uni-forms-item label="栏舍类型" name="phouseType" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="PigLiveList.phouseType"
			 :localdata="phouseTypes"
			 @change="change">
			 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="栏舍编码" name="phouseCode">
		  <uni-easyinput v-model="PigLiveList.phouseCode" placeholder="请输入栏舍编码" />
		</uni-forms-item>
		<uni-forms-item label="健仔数量" name="pigHealthyNum">
		  <uni-easyinput v-model="PigLiveList.pigHealthyNum" placeholder="请输入健仔数量" />
		</uni-forms-item>
		<uni-forms-item label="弱仔数量" name="pigWeakNum">
		  <uni-easyinput v-model="PigLiveList.pigWeakNum" placeholder="请输入弱仔数量" />
		</uni-forms-item>
		<uni-forms-item label="畸形数量" name="pigMalfmNum">
		  <uni-easyinput v-model="PigLiveList.pigMalfmNum" placeholder="请输入畸形数量" />
		</uni-forms-item>
		<uni-forms-item label="死胎数量" name="pigDeadNum">
		  <uni-easyinput v-model="PigLiveList.pigDeadNum" placeholder="请输入死胎数量" />
		</uni-forms-item>
		<uni-forms-item label="母活仔数" name="pigLiveFemaleAliveNum">
		  <uni-easyinput v-model="PigLiveList.pigLiveFemaleAliveNum" placeholder="请输入母活仔数" />
		</uni-forms-item>
		<uni-forms-item label="备注">
			<uni-easyinput type="textarea" v-model="PigLiveList.remark" placeholder="请输入备注内容" />
		</uni-forms-item>
	    </uni-forms>

	    <button type="primary" @click="submit">提交</button>
	  </view>
	</view>

</template>

<script>


import { listPigLive,getPigLive, delPigLive,findAllStaffName, addPigLive, updatePigLive} from "@/api/hmy/pigLive";

export default {
  name: "PigLive",
  dicts: ['hmy_pig_live_type','hmy_park_type'],
  data() {

	return {
			datetimesingle: '',
			PigLiveList: {
				pigCode: "",
				pigFatherCode: "",
				pregnancyDays:"150",
				pigLiveTime: "",
				phouseCode: "",
				pigHealthyNum:"",
				pigWeakNum:"",
				pigMalfmNum:"",
				pigDeadNum:"",
				pigLiveFemaleAliveNum:""

			},
			pigLiveTypes: [{
			  text: ' 顺产',
			  value: "1"
			},
			{
			  text: ' 难产',
			  value: "2"
			},
			{
			  text: ' 助产',
			  value: "3"
			}
			],
			phouseTypes:[{
				text: ' 种猪',
				value: "1"
			},{
				text: ' 母猪',
				value: "2"
			},{
				text: ' 肉猪',
				value: "3"
			}
			],

			rules: {
			  pigCode: {
				rules: [{
				  required: true,
				  errorMessage: '猪只耳号不能为空'
				}]
			  }
			},
		//所有猪只配种负责人
		staffNameList: [],
		}
	  },
	created() {
		findAllStaffName().then(response => {
			var staffList = response.data;
			staffList.forEach(item => {
				this.staffNameList.push({
					'text': item.staffName,
					'value': item.staffId
				})
			})
			//console.log(this.staffNameList);
		})
	},


	  methods: {

		submit(ref) {
		  this.$refs.form.validate().then(res => {
			addPigLive(this.PigLiveList).then(response => {
			  this.$modal.msgSuccess("新增成功")
			})
		  })
		}
	  }
	}
</script>
<style lang="scss">

  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 100%;
    height: auto;
	background-color: #fcfcfc;
  }

  view {
    font-size: 16px;
    line-height: inherit;
  }
  /* #endif */
  .code{
	margin-bottom :5px;
  }
  .icon{
	float:right;
	margin-right:10px;
	margin-top :5px;
  }
  .message{
	margin-top:5px;
	color: #989897;
	line-height: 25px;
  }


  .example {
    padding: 15px;
    background-color: #fff;
  }

  .segmented-control {
    margin-bottom: 15px;
  }

  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
  }

  .form-item {
    display: flex;
    align-items: center;
    flex: 1;
  }

  .button {
    display: flex;
    align-items: center;
    height: 35px;
    line-height: 35px;
    margin-left: 10px;
  }
</style>

